import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  // 帝可得
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '帝可得', icon: 'dashboard' }
    }]
  },

  {
    path: '/tickets',
    component: Layout,
    redirect: '/tickets/operate',
    name: 'Tickets',
    meta: {
      title: '工单管理',
      icon: 'tickets'
    },
    children: [
      {
        path: 'operate',
        component: () => import('@/views/tickets/operate/index'),
        name: 'Operate',
        meta: { title: '运营工单' }
      },
      {
        path: 'operations',
        component: () => import('@/views/tickets/operations/index'),
        name: 'Operations',
        meta: { title: '运维工单' }
      }
    ]
  },

  {
    path: '/gssp',
    component: Layout,
    redirect: '/gssp/zone',
    name: 'Gssp',
    meta: {
      title: '点位管理',
      icon: 'gssp'
    },
    children: [
      {
        path: 'zone',
        component: () => import('@/views/gssp/zone/index'), // Parent router-view
        name: 'Zone',
        meta: { title: '区域管理' }
      },
      {
        path: 'gssps',
        component: () => import('@/views/gssp/gssps/index'),
        name: 'Gssps',
        meta: { title: '点位管理' }
      },
      {
        path: 'partners',
        component: () => import('@/views/gssp/partners/index'),
        name: 'Partners',
        meta: { title: '合作商管理' }
      }
    ]
  },

  {
    path: '/device',
    component: Layout,
    redirect: '/device/devices',
    name: 'Device',
    meta: {
      title: '设备管理',
      icon: 'device'
    },
    children: [
      {
        path: 'devices',
        component: () => import('@/views/device/devices/index'), // Parent router-view
        name: 'Devices',
        meta: { title: '设备管理' }
      },
      {
        path: 'states',
        component: () => import('@/views/device/states/index'),
        name: 'States',
        meta: { title: '设备状态' }
      },
      {
        path: 'dtm',
        component: () => import('@/views/device/dtm/index'),
        name: 'Dtm',
        meta: { title: '设备类型管理' }
      }
    ]
  },

  {
    path: '/people',
    component: Layout,
    redirect: '/people/nearlist',
    name: 'People',
    meta: {
      title: '人员管理',
      icon: 'people'
    },
    children: [
      {
        path: 'nearlist',
        component: () => import('@/views/people/nearlist/index'), // Parent router-view
        name: 'Nearlist',
        meta: { title: '人员列表' }
      },
      {
        path: 'info',
        component: () => import('@/views/people/info/index'),
        name: 'Info',
        meta: { title: '人效统计' }
      },
      {
        path: 'effort',
        component: () => import('@/views/people/effort/index'),
        name: 'Effort',
        meta: { title: '工作量列表' }
      }
    ]
  },

  {
    path: '/article',
    component: Layout,
    redirect: '/article/goodstype',
    name: 'Article',
    meta: {
      title: '商品管理',
      icon: 'article'
    },
    children: [
      {
        path: 'goodstype',
        component: () => import('@/views/article/goodstype/index'),
        name: 'Goodstype',
        meta: { title: '商品类型' }
      },
      {
        path: 'goods',
        component: () => import('@/views/article/goods/index'),
        name: 'Goods',
        meta: { title: '商品管理' }
      }
    ]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/tactics',
    children: [{
      path: 'tactics',
      name: 'Tactics',
      component: () => import('@/views/tactics/index'),
      meta: { title: '策略管理', icon: 'tactics' }
    }]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/order',
    children: [{
      path: 'order',
      name: 'Order',
      component: () => import('@/views/order/index'),
      meta: { title: '订单管理', icon: 'order' }
    }]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/checking',
    children: [{
      path: 'checking',
      name: 'Checking',
      component: () => import('@/views/checking/index'),
      meta: { title: '对账统计', icon: 'checking' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
